﻿using EFCore_Test.AppDBContext.Configuration;
using EFCore_Test.Entities;
using Microsoft.EntityFrameworkCore;

namespace EFCore_Test.AppDBContext
{
    public class ApplicationContext : DbContext
    {
        public ApplicationContext(DbContextOptions options) : base(options)
        {
        }

        //当有多数据上下文时，用泛型版本的构造函数用以区分
        //public ApplicationContext(DbContextOptions<ApplicationContext> options) : base(options)
        //{
        //}

        public DbSet<Account> Accounts { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ApplyConfiguration<Account>(new AccountConfiguration());
            //modelBuilder.Entity<Account>().ToTable("Account");
            //modelBuilder.Entity<Account>().Property(x => x.Id).HasColumnName("AccountId");
            //modelBuilder.Entity<Account>().Property(x => x.Name).IsRequired().HasMaxLength(50);
            //modelBuilder.Entity<Account>().Property(x => x.Age).IsRequired();

            ////种子数据
            //modelBuilder.Entity<Account>().HasData(
            //    new Account
            //    {
            //        Id = Guid.NewGuid(),
            //        Name = "1",
            //        Age = 18
            //    },
            //    new Account
            //    {
            //        Id = Guid.NewGuid(),
            //        Name = "2",
            //        Age = 18
            //    }
            //    ); ;
        }
    }
}